package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.request.CreateOrderReq;
import com.macro.mall.portal.request.QueryOrderReq;
import com.macro.mall.portal.service.WxPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName WxPayService
 * @Package com.macro.mall.portal.service
 * @Description TODO
 * @Author wsx
 * @Date 2024/8/719:18
 * @Version V1.0
 * @Copyright yunshan
 */
@RestController
@Api(tags = "WxPayController")
@Tag(name = "WxPayController", description = "微信支付")
@RequestMapping("/wxpay")
public class WxPayController {

    @Autowired
    private WxPayService wxPayService;

    /***
     * 预支付订单
     * @return
     */
    @ApiOperation("微信预支付订单")
    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    public CommonResult<?> createOrder(CreateOrderReq req) throws Exception {
        return wxPayService.createOrder(req);
    }


    /***
     * 微信支付回调通知
     * @param request
     * @return
     */
    @ApiOperation("微信支付回调")
    @RequestMapping(value = "/payNotify", method = RequestMethod.POST)
    public String payNotify(HttpServletRequest request) throws Exception{
        return wxPayService.payNotify(request);
    }


    /***
     * 根据商户订单号查询订单 outTradeNo
     * @param req
     * @return
     */
    @ApiOperation("微信商户订单号查询订单 outTradeNo")
    @RequestMapping(value = "/queryOrderByOrderNo", method = RequestMethod.GET)
    public CommonResult<Object> queryOrderByOrderNo(QueryOrderReq req) {
        return wxPayService.queryOrderByOrderNo(req);
    }


    /***
     * 根据支付订单号查询订单 paymentNo
     * @param req
     * @return
     */
    @ApiOperation("微信根据支付订单号查询订单 paymentNo")
    @RequestMapping(value = "/queryOrderByPaymentNo", method = RequestMethod.GET)
    public CommonResult<Object> queryOrderByPaymentNo(QueryOrderReq req){
        return null;
    }


    /***
     * 微信申请退款
     * @param outTradeNo 商户订单号
     * @param totalAmount
     * @return
     */
    @ApiOperation("微信申请退款")
    @RequestMapping(value = "/createRefund", method = RequestMethod.GET)
    public CommonResult<Object> createRefund(String outTradeNo, Long totalAmount){
        return null;
    }
}
